
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<script language="JavaScript" type="text/javascript" src="../javascript/caltimer.js"></script>
<script language="JavaScript" type="text/javascript" src="../javascript/ajaxdeal.js"></script>
<html:form action="register/registeraction">
<input type="hidden" name="steptype" value="4"/>
<div id="regright">
  
   <table width="610" border="0" cellpadding="0" cellspacing="0">
          <tr class="th_bj">
            <td width="105" height="28" align="center"> <span class="f-12-b-ffffff">姓名*</span></td>
            <td width="89" height="28" align="center"  ><span class="f-12-b-ffffff">手机*</span></td>
            <td width="80" height="28" align="center"  ><span class="f-12-b-ffffff">邮箱*</span></td>
            <td width="80" height="28" align="center"  ><span class="f-12-b-ffffff">传真</span></td>
            <td width="100" height="28" align="center"  ><span class="f-12-b-ffffff">邮政编码</span></td>
            <td width="100" height="28" align="center"  ><span class="f-12-b-ffffff">通讯地址</span></td>
			<td align="center" width="30"><img src="../images/botton_add.jpg"  border="0" onclick="addRow()" style="cursor:hand"/>
          </tr>
   </table>
	<table width="610" border="0" cellpadding="0" cellspacing="0" id="fileuploadtable">
	           <logic:iterate id="supagent" name="contacts">
	           <tr id="row${supagent.pk_contact_info_id }">
	            <td height="35" align="center">
	            	<input name='contact_pk_contact' type="hidden"  value="${supagent.pk_contact_info_id }"/>
	            	<input name='contact_contact_name' type='text'  style='width:80px' value="${supagent.contactname }"/>
	            </td>
	            <td align="center" ><input name='contact_phone' type='text'  style='width:80px'  value="${supagent.phone1 }" /></td>
	            <td align="center" ><input name='contact_email' type='text'  style='width:80px' value="${supagent.email }"/></td>
	            <td align="center" ><input name='contact_fax' maxlength='30' type='text'  style='width:80px' value="${supagent.fax }" /></td>
	            <td align="center" ><input name='contact_address' maxlength="6" type='text' onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46" style='width:80px;ime-mode:Disabled;' value="${supagent.postcode}" /></td>
	            <td align="center" ><input name='contact_postaddress' type='text' style='width:100px' value="${supagent.postaddress}" /></td>
	            <td align="center"><img src='../images/botton_delete.jpg' style='cursor:hand' border=0 style='cursor:hand' onclick="deleteRow('${supagent.pk_contact_info_id}')"/></td>
	          </tr>
	          </logic:iterate>
	</table>
        
  <table>
  <tr>
    <td colspan="4" class="f-12-F60000">提示：带“*”的为必填信息；若界面显示不全面，请先设置IE浏览器到兼容性视图，具体操作请见首页相关操作手册。</td>
    </tr>
  <tr>
    <td colspan="4" class="center">
    <img style="cursor:hand" src="../images/up.jpg" width="60" height="20" onclick="up(3)"/>&nbsp;&nbsp;<img style="cursor:hand" src="../images/next.jpg" width="60" height="20" border="0" onclick="onclicksubmit()"/>&nbsp;&nbsp;<img style="cursor:hand" src="../images/reset.jpg" width="60" height="20" onclick="reset()"/></td>
    </tr>
  </table>
</div>
</html:form>

<input type="text" style="display:none" id="removefocuse"/>
<script language="javascript">
	function up(index)
	{
		window.location.href = "/portal/register/registeraction.do?uptype="+index;
	}
	function reset()
	{
		document.registerForm.reset();
	}
	
	function isEmail(email){
	 //var myreg = /^([a-zA-Z0-9]+[_|\_|\.-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.-]?)*[a-zA-Z0-9]?\.[a-zA-Z]{2,6}$/;
		if(email==""){
			alert('邮箱不能为空！');
	        return false;
		}
		var myreg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if(!myreg.test(email))
	    {
	           alert('请输入有效的邮箱！');
	           return false;
	     }else{
	     	return true;
	     }
	
	}
	
	function isTel(s){
		//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
		if(s==""){
			alert('电话不能为空！');
	        return false;
		}
		var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
		if (!patrn.exec(s)) return false
		return true
	}
		
	function onclicksubmit()
	{
	
	var formtemp = document.registerForm;
	
	var contactname = document.getElementsByName("contact_contact_name");
	var contactphone = document.getElementsByName("contact_phone");
	var contactemail = document.getElementsByName("contact_email");
	if(contactname.length == 0){
		alert("请添加联系人！");
		return;
	}
	for(var index = 0; index < contactname.length; index++){
	
		if(contactname[index].value == "" || contactname[index].value.length > 20 ){
			alert("必须填写姓名，或者你的名字超长了!");
			return;
		}else if(!isTel(contactphone[index].value) || contactphone[index].value.length > 16){
			if(contactphone[index].value.length > 16 || contactphone[index].value.length > 0)
				alert("请输入正确的电话号码，或者你的电话超长了!");
			return;
		}else if(!isEmail(contactemail[index].value)){
			return;
		}
	}
	
	/*
	
	if(formtemp.businessinfo.value == '')
	{
		formtemp.businessinfo.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.customer.value == '')
	{
		formtemp.customer.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.product.value == '')
	{
		formtemp.product.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.sales_ablity_desc.value == '')
	{
		formtemp.sales_ablity_desc.style.backgroundColor="#ffaa44";
		return;
	}
	*/
	
	
		formtemp.submit();
	}
	
	/*
	else if(formtemp.quality.value == '')
	{
		formtemp.quality.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.sales_ablity.value == '')
	{
		formtemp.sales_ablity.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.supply_ablity.value == '')
	{
		formtemp.supply_ablity.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.supply_cycle.value == '')
	{
		formtemp.supply_cycle.style.backgroundColor="#ffaa44";
		return;
	}else if(formtemp.bill_method.value == '')
	{
		formtemp.bill_method.style.backgroundColor="#ffaa44";
		return;
	}
	*/
	
	function onblurdo(obj)
	{
		if(obj.value == '' )
		{
			obj.style.backgroundColor="#ffaa44";
		}else
		{
			obj.style.backgroundColor="#ffffff";
		}
	}
	function submitMess()
	{
	var formtemp = document.registerForm;
	var contactname = document.getElementsByName("contact_contact_name");
	var contactphone = document.getElementsByName("contact_phone");
	var contactemail = document.getElementsByName("contact_email");
	
	
	for(var index = 0; index < contactname.length; index++){
	
	
		if(contactname[index].value == "" || contactname[index].value.length > 20 ){
			alert("必须填写姓名，或者你的名字超长了!");
			return;
		
		}else if(!isEmail(contactemail[index].value)){
		
			return;
		}else if(!isTel(contactphone[index].value) || contactphone[index].value.length > 16){
			alert("请输入正确的电话号码，或者你的电话超长了!");
			return;
		}
	}
	
	parent.showHideFun();
	parent.changeShowMessage("请确认是否已经保存了信息!","yes","warn",twiFun);
	}
	
	function twiFun(){
	
		var url = "modifyperson.do?steptype=5&random"+Math.random();
		parent.showHideFun();
		parent.changeShowMessage("提交数据开始,请等待......");
		ajax(url,returnFunction);
	}
	
	function returnFunction(value)
	{
	if(value != null)
	{
		if(value == "ok")
		{
			parent.changeShowMessage("数据提交成功!",'yes','ok');	
		}else
		{
			parent.changeShowMessage("数据提交失败,请重新提交!",'yes','ok');	
		}
	}else
	{
		parent.changeShowMessage("数据提交失败,请重新提交!",'yes','ok');	
		
	}
	}
	
	var rowindex=0;
	//向批量上传文件的列表中添加一行数据
	function addRow()
	{
	
	 var root = document.getElementById("fileuploadtable");
	 var row = root.insertRow();
	 row.style.height = '26px';
	 rowindex++;
	 row.id = "row"+rowindex;
	
	 var cell1 = row.insertCell();
	 cell1.align="center";
	 cell1.innerHTML = "<input name='contact_pk_contact' type='hidden'  value=' '/><input name='contact_contact_name' type='text'  size='13' style='width:80px'/>";
	 
	
	 var cell2 = row.insertCell();
	 cell2.align="center";
	 cell2.innerHTML = "<input name='contact_phone' type='text'   style='width:80px' />";
	 
	 var cell4= row.insertCell();
	 cell4.align="center";
	 var innercontent = "<input name='contact_email' type='text'  style='width:80px' />";
	 cell4.innerHTML = innercontent;
	 
	
	 var cell5 = row.insertCell();
	 cell5.align="center";
	 cell5.innerHTML = "<input name='contact_fax' maxlength='30' type='text'  style='width:80px'/>";
	 
	  var cell6 = row.insertCell();
	 cell6.align="center";
	 cell6.innerHTML = "<input name='contact_address' maxlength='6' type='text'   style='width:80px' />";
	 
	 
	  var cell7 = row.insertCell();
	 cell7.align="center";
	 cell7.innerHTML = "<input name='contact_postaddress' type='text'   style='width:100px'/>";
	 
	
	 var cell3 = row.insertCell();
	 cell3.align="center";
	 var img = "<img src='../images/botton_delete.jpg' style='cursor:hand' border=0 style='cursor:hand' onclick='deleteRow("+rowindex+")'/>";
	 cell3.innerHTML = img;   
	}
	
	//删除上传文件
	function deleteRow(index)
	{
		var root = document.getElementById("fileuploadtable");
		var row = "row"+index ;
		
		var rows = root.rows;
		var deletepos = 0;
		
		
		//寻找到对应的删除行并进行删除
		for(var pos = 0; pos < rows.length; pos++)
		{
			var temprow = rows[pos];
			if(temprow.id == row)
			{
				root.deleteRow(pos);
				deletepos = pos;
				rowindex--;
				break;
			}
		}
	}
</script>
